package com.xxl.job.executor.mvc.controller;

import com.xxl.job.executor.service.jobhandler.SampleXxlJob;
import com.xxl.job.executor.service.jobhandler.XxlJobInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
//@EnableAutoConfiguration
public class IndexController {


    @Autowired
    SampleXxlJob job;

    @RequestMapping("/")
    @ResponseBody
    String index() {
        return "xxl job executor running.";
    }

    @GetMapping("/add/{id}")
    @ResponseBody
    public String add(@PathVariable("id") Integer id) {
        return job.add(id);
    }

    @GetMapping("/update/{id}/{jobGroup}")
    @ResponseBody
    public String update(@PathVariable("id") int id, @PathVariable("jobGroup") int jobGroup) {
        String cron = "0/10 * * * * ?";
        return job.update(id, cron, jobGroup);
    }

    @GetMapping("/remove/{id}")
    @ResponseBody
    public String remove(@PathVariable("id") int id) {
        return job.remove(id);
    }

    @GetMapping("/stop/{id}")
    @ResponseBody
    public String stop(@PathVariable("id") int id) {
        return job.stop(id);
    }

    @GetMapping("/start/{id}")
    @ResponseBody
    public String start(@PathVariable("id") int id) {
        return job.start(id);
    }

    @GetMapping("/addAndStart/{id}")
    @ResponseBody
    public String addAndStart(@PathVariable("id") int id) {
        return job.addAndStart(id);
    }


}